if '__main__' == __name__:

    import pandas as pd
    import os
    from PyCmpltrtok.common import sep
    import json

    def _main():

        csv_dir = r'D:\_dell7590_root\sync\1_usb\M2\N5\x00700 农业知识图谱'

        csv_name_list = [
            'attributes.csv',
            'city_weather.csv',
            'weather_plant.csv',
            'wikidata_relation.csv',
            'wikidata_relation2.csv',
        ]

        xname2relations = dict()

        for csv_name in csv_name_list:
            sep(csv_name)
            csv_path = os.path.join(csv_dir, csv_name)

            # 加载
            df = pd.read_csv(csv_path, delimiter=',', header=0)

            # 数据量
            xcount = len(df)
            print('Data count:', csv_path, xcount)

            # 所有关系
            # https://stackoverflow.com/questions/48641632/extracting-specific-columns-from-pandas-dataframe
            relation_list = df[df.columns[1]].tolist()
            # 转str
            relation_list = [str(x) for x in relation_list]
            # 去重+排序
            relation_list = sorted(set(relation_list))

            # 关系量
            xrel_count = len(relation_list)
            print('Relationships count:', xrel_count)

            # 放入字典
            xname2relations[csv_name] = {
                'record_count': xcount,
                'relationships': relation_list,
                'relationships_count': xrel_count,
            }

        # 结果写入JSON文件
        with open('check_result.tmp.json', 'w', encoding='utf8') as f:
            json.dump(xname2relations, f)

    _main()
